package com.swt.testdemo.controller;

import com.swt.testdemo.config.ResponseBean;
import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.form.AddLawForm;
import com.swt.testdemo.form.AddLawLabelForm;
import com.swt.testdemo.form.CreateLawTemplateForm;
import com.swt.testdemo.form.EditSysDataLawTemplateForm;
import com.swt.testdemo.form.QueryLawForm;
import com.swt.testdemo.form.QueryTemplateForm;
import com.swt.testdemo.service.SysDataLawService;
import com.swt.testdemo.service.SysDataLawTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/16 9:11
 **/
@RestController
@RequestMapping("sys-dataLaw")
@Slf4j
@Api(tags = "后台管理--法律法规管理")
public class SysDataLawController {

    @Autowired
    private SysDataLawTemplateService sysDataLawTemplateService;


    @Autowired
    private SysDataLawService sysDataLawService;

    @ApiOperation("01 获取法律法规模板列表")
    @GetMapping(value = "/template-list")
    public ResponseEntity<ResponseBean>  getTemplateList(QueryTemplateForm form){
        ResponseBean response = sysDataLawTemplateService.getTemplateList(form);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("02 查看法律法规模板详情")
    @GetMapping(value = "/template")
    @ApiImplicitParam(name = "lawTemplateId",value = "法律法规模板Id",paramType = "query",dataType = "int",defaultValue = "1")
    public ResponseEntity<ResponseBean> getTemplateInfo(Integer lawTemplateId){
        ResponseBean response = sysDataLawTemplateService.getTemplateInfo(lawTemplateId);
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("03 创建法律法规模板")
    @PostMapping("/template-create")
    public ResponseEntity<ResponseBean> createTemplate(CreateLawTemplateForm form){
        ResponseBean response = sysDataLawTemplateService.createTemplate(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }

     @ApiOperation("04 编辑法律法规模板")
     @PostMapping("/template-edit")
     public ResponseEntity<ResponseMessage> editTemplate(@RequestBody EditSysDataLawTemplateForm form){
         ResponseMessage response = sysDataLawTemplateService.editTemplate(form);
         return ResponseEntity.status(response.getStatus()).body(response);

     }

     @ApiOperation("05 删除法律法规模板")
     @DeleteMapping("/template-del")
     @ApiImplicitParam(name = "dataTemplateId",value = "法律法规模板数据id",paramType = "query",dataType = "int",example = "1")
     public  ResponseEntity<ResponseMessage> delTemplate(Integer dataTemplateId){
         ResponseMessage response = sysDataLawTemplateService.delTemplate(dataTemplateId);
         return ResponseEntity.status(response.getStatus()).body(response);
     }


     @ApiOperation("06 获取法律法规列表")
     @GetMapping("/list")
     public ResponseEntity<ResponseBean> getLawList(QueryLawForm form){

         ResponseBean response = sysDataLawService.getLawList(form);
         return ResponseEntity.status(response.getStatus()).body(response);

     }

    @ApiOperation("08 手动新增法律法规（完成）")
    @PostMapping(value = "/manual-add")

    public ResponseEntity<ResponseBean> manualAddLaw(@RequestBody AddLawForm form) {
        ResponseBean response = sysDataLawService.addLaw(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }


     @ApiOperation("08 删除法律法规")
     @DeleteMapping(value = "/law-remove")
     @ApiImplicitParam(name = "lawId",value = "法律法规id",paramType = "query",dataType = "int",example = "1")
     public ResponseEntity<ResponseMessage> removeLaw(Integer lawId){
         ResponseMessage response = sysDataLawService.removeLaw(lawId);
         return ResponseEntity.status(response.getStatus()).body(response);

     }


    @ApiOperation("09 查看法律法规详情")
    @GetMapping(value = "/law-info")
    @ApiImplicitParam(name = "lawId",value = "法律法规id",paramType = "query",dataType = "int",defaultValue = "1")
    public ResponseEntity<ResponseBean> getLawInfo(Integer lawId){
        ResponseBean response = sysDataLawService.getLawInfo(lawId);
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("10 法律法规添加标签")
    @PostMapping(value = "/add-label")
    public ResponseEntity<ResponseBean> addLawLabel(@RequestBody AddLawLabelForm form){

        ResponseBean response = sysDataLawService.addLawLabel(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }
}
